\documentclass[12pt,english,fleqn,liststotoc,bibtotoc,idxtotoc,BCOR7.5mm,tablecaptionabove]{article}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage[a4paper]{geometry}
\geometry{verbose,tmargin=3cm}
\setlength{\parskip}{\medskipamount}
\setlength{\parindent}{0pt}
\usepackage{color}
\usepackage{babel}
\usepackage{float}
\usepackage[unicode=true,
 bookmarks=true,bookmarksnumbered=true,bookmarksopen=true,bookmarksopenlevel=1,
 breaklinks=false,pdfborder={0 0 1},backref=false,colorlinks=true]
 {hyperref}
\hypersetup{pdftitle={Distributed System},
 pdfauthor={Chen Wei},
 linkcolor=black, citecolor=blue, anchorcolor=blue, urlcolor=blue, filecolor=blue,pdfpagelayout=OneColumn, pdfnewwindow=true,pdfstartview=XYZ, plainpages=false}

\makeatletter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
\usepackage{graphicx}
\pagestyle{empty}

\makeatother

\begin{document}

\title{Task 2}


\author{CS M1 201120784 Chen Wei}

\maketitle

\begin{itemize}
\item Modify Listing 29.1
\begin{itemize}
\item After running this program, character 'a', 'b', 
and 'c' are printed 100 times each. On my two-core 
laptop, only two threads run simultaneously, and each
thread runs a fixed time slice on CPU. Therefore, the
result could be printing one character several times,
and then another character several times, and then 
another character several times till the end of each
printing. 
\item After adding {\tt yield()} to each printing of 'a',
when running the program in my machine, task {\tt printA} 
prints 'a' one time and releases its CPU time from one
core and is picked up to another core by the OS. So the
result could be printing 'a' several times, and then show
interleaved printing for character 'a', 'b', and 'c' each
several times till the end of each printing. And finally
the main thread prints ``All threads finish!'' since it
invokes {\tt join()} for each thread.
\item After adding {\tt sleep(10)} to each printing of 'a',
when running the program, task {\tt printA} prints one 'a'
and goes to sleep. Then task {\tt printB} and {\tt printC}
show interleaved printing of 'b' and 'c'. At last, the 
left 'a's are printed followed by ``All threads finish!''.
\item After setting the priority of {\tt printA}'s thread
to {\tt MAX}, and the priority of {\tt printC}'s thread to
{\tt MIN}, the result shows that character 'a' is printed
100 times, and then 'b' interleaves with several 'c', and
finally all left 'c's are printed out followed by ``All
threads finish!''.

\end{itemize}

\end{itemize}

\end{document}
